

function tryInitSocket (e) {

    var address = (e.currentTarget.value) ;
    address = (address.match(/\d{1,2}/));
    if (address) {
	if( localStorage["sandbox"] == "true" ) {
	    $("#GoButton2").prop( "disabled", false );
	} else {
	    $("#GoButton1").prop( "disabled", false );
	}
        localStorage["groupeId"]=address;
        localStorage["name"]= $("#name").val() || "Anonymous" + ~~(Math.random() *1000) ; 
	

    }
}
var countDown = 60 ; 
var countDownInterval = 0 ; 
function startCountDown () {
    $("#brique").unbind( "keyup", startCountDown ) ; 
    countDownInterval = setInterval( function() {
	countDown-- ; 
	$("#remainingTime").text( countDown ) ; 
	if( !countDown ) { 
	    clearInterval( countDownInterval ) ; 
	     $("#briqueNext").prop( "disabled", false );
	    $("#brique").prop( "disabled",true );
	}
	
    }, 1000 )
}

function gatherInfo() {
    var namedElement = $("*[name]")
    
}

function boot() {




$("#name").val(localStorage["name"]|| "Anonymous" + ~~(Math.random() *1000))
$("#serveurAddress")
    .change(tryInitSocket)
    .keyup(tryInitSocket)
    .blur(tryInitSocket)
    .focus(tryInitSocket)
    .val(localStorage["groupeId"]||"")


    
    $("#infoBox").css("display", "block")
    $("#introNext").click(function(e){  
	window.location.assign( window.location.origin + "/questionnaire.html" ) ;
	return false ;
    })
    $("#questionNext").click(function(e){  
	window.location.assign( window.location.origin + "/brique.html" ) ;
	return false ;
    })
    $("#briqueNext").click(function(e){  
	window.location.assign( window.location.origin + "/echauffement.html" ) ;
	return false ;
    })
    

    $("#GoButton1").click(function(){  
	localStorage["sandbox"] =  true ; 
	window.location = window.location.origin + '/clients/html/simple.html' 
    })
    $("#GoButton2").click(function(){ 
	localStorage["sandbox"] =  false ; 
	window.location = window.location.origin + '/clients/html/simple.html' 
    })
    $("a").click( function () {
	console.log("hello") ;
localStorage["sandbox"] =  false ; 

	$("#GoButton2").prop( "disabled", true );
	$("#GoButton1").prop( "disabled", false );

	event.stopPropagation() 
	return false ; 
    })

    
    $("#brique").keyup( startCountDown ) ;
}
$(document).ready(boot);
